<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_forum
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');

// Create shortcut to parameters.
$params = $this->state->get('params');
if(isset($this->topic->images)): 
$images = json_decode($this->topic->images);
endif;
?>

<script type="text/javascript">
	Joomla.submitbutton = function(task) {
		if (task == 'post.cancel' || document.formvalidator.isValid(document.id('adminForm'))) {
			Joomla.submitform(task);
		}
		else {
			alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
		}
	}
</script>

<div class="forum-category-home">
<h1>
	<?php echo JHtml::_('content.prepare', $this->category->title, '', 'com_forum.category'); ?>
</h1>

<?php if($this->topic): ?>
<div class="forum-left">
<h3 class="topic-title">
<?php echo $this->topic->title ?>
</h3>
<?php  if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<div class="topic-image">
<img
	src="<?php echo htmlspecialchars($images->image_intro); ?>" />
</div>
<?php endif; ?>

<div class="topic-description">
<?php if(strpos($this->topic->description, '<hr id="system-readmore" />') === false): ?>
<?php echo $this->topic->description; ?>
<?php else: ?>
<?php echo substr($this->topic->description, 0, strpos($this->topic->description, '<hr id="system-readmore" />')) ?><a href="<?php echo JRoute::_(('index.php?option=com_forum&view=topic&catid='.$this->topic->catid.'&id=' .$this->topic->id));?>" class="read-more"><?php echo JText::_("COM_FORUM_MESSAGE_READ_MORE") ?></a>
<?php endif; ?>
</div>
</div>

<div class="forum-right">
<?php if(count($this->posts) > 0) : ?>
<h3><?php echo JText::_("COM_FORUM_MESSAGE_LIST") ?></h3>
<div class="posts-list">
<ul>
<?php foreach($this->posts as $post): ?>
<li><a href="<?php echo JRoute::_(('index.php?option=com_forum&view=topic&catid='.$this->topic->catid.'&id=' .$this->topic->id .'#'.$post->id));?>"><?php echo $post->title ?></a> (<?php echo JText::_("by:") ?> <?php echo ($post->created_by == 0)? $post->created_by_alias : $post->author_name; ?>) </li>
<?php endforeach; ?>
</ul>
<a href="<?php echo JRoute::_(('index.php?option=com_forum&view=topic&catid='.$this->topic->catid.'&id=' .$this->topic->id));?>"><?php echo JText::_("Continue") ?></a>
<a href="<?php echo JRoute::_(('index.php?option=com_forum&view=post&layout=add&catid='.$this->topic->catid.'&tid=' .$this->topic->id));?>"><?php echo JText::_("Reply") ?></a>

</div>
<?php endif; ?>

<div class="posts-form">
<h3><?php echo JText::_("COM_FORUM_MESSAGE_REPLY_TITLE") ?></h3>

<form action="<?php echo JRoute::_(('index.php?option=com_forum&view=topic&catid='.$this->topic->catid.'&id=' .$this->topic->id));?>" id="adminForm"method="post" >
<input type="hidden" name="task" value="" />
<input type="hidden" name="jform[tid]" value="<?php echo $this->topic->id ?>" />
<input type="hidden" name="jform[catid]" value="<?php echo $this->topic->catid ?>" />


<fieldset>

			<div class="formelm">
				<label id="jform_created_by_alias-lbl" for="jform_created_by_alias" class="hasTip required" title="<?php echo JText::_("COM_FORUM_CREATED_BY_ALIAS_LABEL") ?>::<?php echo JText::_("COM_FORUM_CREATED_BY_ALIAS_DESC") ?>"><?php echo JText::_("COM_FORUM_CREATED_BY_ALIAS_LABEL") ?><span class="star">&#160;*</span></label>				<input type="text" name="jform[created_by_alias]" id="jform_created_by_alias" value="<?php echo $this->user->get('name') ?>" class="inputbox validate-title required" size="20"/>			</div>

			<div class="formelm">
			<label id="jform_title-lbl" for="jform_title" class="hasTip required" title="Title::Your Web Link must have a Title."><?php echo JText::_("COM_FORUM_POST_FIELD_MESSAGE_LABEL") ?><span class="star">&#160;*</span></label>			<textarea name="jform[message]" id="jform_message" value="" class="required" size="30"/></textarea>			</div>

		<?php if ($recaptcha = ForumHelper::getRecaptcha()) : ?>
			<div class="formelm">
			<label id="jform_captcha-lbl" for="jform_capthca" class="hasTip required" title="Captcha::<?php echo JText::_("COM_FORUM_POST_FIELD_CAPTCHA_DESC") ?>"><?php echo JText::_("COM_FORUM_POST_FIELD_CAPTCHA_LABEL") ?><span class="star">&#160;*</span></label>
					<script type="text/javascript"
						src="http://www.google.com/recaptcha/api/challenge?k=<?php echo $recaptcha->publicKey; ?>">
					</script>
					<noscript>
						<iframe src="http://www.google.com/recaptcha/api/noscript?k=<?php echo $recaptcha->publicKey; ?>"
							height="300" width="500" frameborder="0"></iframe><br>
						<textarea name="recaptcha_challenge_field" rows="3" cols="40">
						</textarea>
						<input type="hidden" name="recaptcha_response_field"
							value="manual_challenge">
					</noscript>
			</div>
		<?php endif; ?>			
			
			<div class="formelm-buttons">
			<button type="button" onclick="Joomla.submitbutton('post.save')">
				<?php echo JText::_("COM_FORUM_SAVE") ?>			</button>
			<button type="button" onclick="Joomla.submitbutton('post.cancel')">
				<?php echo JText::_("COM_FORUM_CANCEL") ?>			</button>
			</div>

		<?php echo JHtml::_( 'form.token' ); ?>
</fieldset>
</form>
</div>
<?php else: ?>
<p>
<?php echo JText::_("There is no topic in this category") ?>
</p>
<?php endif; ?>
</div>
</div>
